function Menu_Inventory()
{
  RenderMap();
  
  WindowStyle.drawWindow(8, 8, 624, 12);
  Font.drawText(10, 10, "Inventories:");

  // execute the menu
  var ItemMenu = new Menu();
  ItemMenu.font         = Font;
  ItemMenu.window_style = WindowStyle;
  ItemMenu.arrow        = Arrow;
  ItemMenu.addItem("Armour", MenuArmour);
  ItemMenu.addItem("Weapons", MenuWep);
  ItemMenu.addItem("Items", MenuItems);
  ItemMenu.addItem("Cancel", GameMenu);
  ItemMenu.execute(6, 34, 272, 140);
}
function MenuArmour()
{
  RenderMap();
  
  WindowStyle.drawWindow(8, 8, 624, 12);
  Font.drawText(10, 10, "Armour Inventory:");

  // execute the menu
  var ItemMenu = new Menu();
  ItemMenu.font         = Font;
  ItemMenu.window_style = WindowStyle;
  ItemMenu.arrow        = Arrow;
  if (Playerweapons.Lh_Armour > 0)
  {
  ItemMenu.addItem("Leather Armour", MenuArmour_LhArmour);
  }
  if (Playerweapons.StudLh_Armour > 0)
  {
  ItemMenu.addItem("Studded Leather Armour", MenuArmour_StudLhArmour);
  }
  if (Playerweapons.IronPlate > 0)
  {
  ItemMenu.addItem("Iron Plate", MenuArmour_IronPlate);
  }
  if (Playerweapons.SilverVest > 0)
  {
  ItemMenu.addItem("Silver Vest", MenuArmour_SilverVest);
  }
  if (Playerweapons.SilverPlate > 0)
  {
  ItemMenu.addItem("Silver Plate", MenuArmour_SilverPlate);
  }
  if (Playerweapons.SteelPlate > 0)
  {
  ItemMenu.addItem("Steel Plate", MenuArmour_SteelPlate);
  }
  if (Playerweapons.BronzeVest > 0)
  {
  ItemMenu.addItem("Bronze Vest", MenuArmour_BronzeVest);
  }
  if (Playerweapons.BronzePlate > 0)
  {
  ItemMenu.addItem("Bronze Plate", MenuArmour_BronzePlate);
  }
  if (Playerweapons.MithrilVest > 0)
  {
  ItemMenu.addItem("Mithril Vest", MenuArmour_MithrilVest);
  }
  if (Playerweapons.MithrilPlate > 0)
  {
  ItemMenu.addItem("Mithril Plate", MenuArmour_MithrilPlate);
  }
  if (Playerweapons.GoldPlate > 0)
  {
  ItemMenu.addItem("Gold Plate", MenuArmour_GoldPlate);
  }
  if (Playerweapons.PlatinumPlate > 0)
  {
  ItemMenu.addItem("Platinum Plate", MenuArmour_PlatinumPlate);
  }
  if (Playerweapons.AdamantinePlate > 0)
  {
  ItemMenu.addItem("Adamantine Plate", MenuArmour_AdamantinePlate);
  }
  if (Playerweapons.AncientPlate > 0)
  {
  ItemMenu.addItem("Ancient Plate", MenuArmour_AncientPlate);
  }
  if (Playerweapons.Cloak > 0)
  {
  ItemMenu.addItem("Cloak", MenuArmour_Cloak);
  }
  if (Playerweapons.CottonRobe > 0)
  {
  ItemMenu.addItem("Cotton Robe", MenuArmour_CottonRobe);
  }
  if (Playerweapons.SilkRobe > 0)
  {
  ItemMenu.addItem("Silk Robe", MenuArmour_SilkRobe);
  }
  if (Playerweapons.DemonPlate > 0)
  {
  ItemMenu.addItem("Demon Plate", MenuArmour_DemonPlate);
  }
  if (Playerweapons.AnglicPlate > 0)
  {
  ItemMenu.addItem("Anglic Plate", MenuArmour_AnglicPlate);
  }

  ItemMenu.addItem("Cancel", GameMenu);
  ItemMenu.execute(6, 34, 272, 140);
}
function MenuArmour_LhArmour()
{
InventoryItem("Leather Armour", Playerweapons.Lh_Armour, "Basic leather armour.", "Defense: 20");
}
function MenuArmour_StudLhArmour()
{
InventoryItem("Studded Leather Armour", Playerweapons.StudLh_Armour, "Leather armour with metal studs embedded in it to increase it's defensive abilities.", "Defense: 25");
}
function MenuArmour_IronPlate()
{
InventoryItem("Iron Plate", Playerweapons.IronPlate, "A simple set of plate mail made of iron.", "Defense: 32");
}
function MenuArmour_SilverVest()
{
InventoryItem("Silver Vest", Playerweapons.SilverVest, "A vest made out of durable silver.", "Defense: 42");
}
function MenuArmour_SilverPlate()
{
InventoryItem("Silver Plate", Playerweapons.SilverPlate, "A set of plate mail made of silver.", "Defense: 50");
}
function MenuArmour_SteelPlate()
{
InventoryItem("Steel Plate", Playerweapons.SteelPlate, "A set of plate mail made of a stronger alloy of iron.", "Defense: 59");
}
function MenuArmour_BronzeVest()
{
InventoryItem("Bronze Vest", Playerweapons.BronzeVest, "A vest made out of an alloy of copper.", "Defense: 70");
}
function MenuArmour_BronzePlate()
{
InventoryItem("Bronze Plate", Playerweapons.BronzePlate, "Made like the bronze vest, but with added protection to more areas of the body.", "Defense: 77");
}
function MenuArmour_MithrilVest()
{
InventoryItem("Mithril Vest", Playerweapons.MithrilVest, "A vest made from the strong metal alloy containing mithril and iron.", "Defense: 95");
}
function MenuArmour_MithrilPlate()
{
InventoryItem("Mithril Plate", Playerweapons.MithrilPlate, "A strong set of plate mail made from a mithril-iron alloy.", "Defense: 115");
}
function MenuArmour_GoldPlate()
{
InventoryItem("Gold Plate", Playerweapons.GoldPlate, "A set of plate mail made from an alloy of gold and mithril.", "Defense: 132");
}
function MenuArmour_PlatinumPlate()
{
InventoryItem("Platinum Plate", Playerweapons.PlatinumPlate, "A set of plate mail made from an alloy of platinum and mithril.", "Defense: 152");
}
function MenuArmour_AdamantinePlate()
{
InventoryItem("Adamantine Plate", Playerweapons.AdamantinePlate, "A set of plate mail made from the rare metal adamantine.", "Defense: 202");
}
function MenuArmour_AncientPlate()
{
InventoryItem("Ancient Plate", Playerweapons.AncientPlate, "A set of plate made long ago with amazing defensive abilities.", "Defense: 250");
}
function MenuArmour_Cloak()
{
InventoryItem("Cloak", Playerweapons.Cloak, "A piece of clothing worn over the back.", "Defense: 9");
}
function MenuArmour_CottonRobe()
{
InventoryItem("Cotton Robe", Playerweapons.CottonRobe, "A robe made of regular cotton.", "Defense: 17");
}
function MenuArmour_SilkRobe()
{
InventoryItem("Silk Robe", Playerweapons.SilkRobe, "A fairly expensive robe that endows the wearer with style.", "Defense: 35");
}
function MenuArmour_DemonPlate()
{
InventoryItem("Demon Plate", Playerweapons.DemonPlate, "A light set of plate that can only be used by mages.", "Defense: 75, Black Magic Power: + 50%");
}
function MenuArmour_AnglicPlate()
{
InventoryItem("Anglic Plate", Playerweapons.AnglicPlate, "A light set of plate that can only be used by mages.", "Defense: 75, White Magic Power: + 50%");
}

function MenuWep()
{
  RenderMap();
  
  WindowStyle.drawWindow(8, 8, 624, 12);
  Font.drawText(10, 10, "Weapons Inventory:");

  // execute the menu
  var ItemMenu = new Menu();
  ItemMenu.font         = Font;
  ItemMenu.window_style = WindowStyle;
  ItemMenu.arrow        = Arrow;
  if (Playerweapons.Dagger > 0)
  {
  ItemMenu.addItem("Dagger", MenuWep_Dagger);
  }
  if (Playerweapons.Dirk > 0)
  {
  ItemMenu.addItem("Dirk", MenuWep_Dirk);
  }
  if (Playerweapons.Short_Sword > 0)
  {
  ItemMenu.addItem("Short Sword", MenuWep_Short_Sword);
  }
  if (Playerweapons.MithrilKnife > 0)
  {
  ItemMenu.addItem("MithrilKnife", MenuWep_MithrilKnife);
  }
  if (Playerweapons.ConqudorKnife > 0)
  {
  ItemMenu.addItem("ConqudorKnife", MenuWep_ConqudorKnife);
  }
  if (Playerweapons.Long_Sword > 0)
  {
  ItemMenu.addItem("Long Sword", MenuWep_Long_Sword);
  }
  if (Playerweapons.BroadSword > 0)
  {
  ItemMenu.addItem("Broad Sword", MenuWep_BroadSword);
  }
  if (Playerweapons.RegalSword > 0)
  {
  ItemMenu.addItem("Regal Sword", MenuWep_RegalSword);
  }
  if (Playerweapons.MithrilBlade > 0)
  {
  ItemMenu.addItem("Mithril Blade", MenuWep_MithrilBlade);
  }
  if (Playerweapons.AdamantineBlade > 0)
  {
  ItemMenu.addItem("Adamantine Blade", MenuWep_AdamantineBlade);
  }
  if (Playerweapons.LegendSword > 0)
  {
  ItemMenu.addItem("Legend Sword", MenuWep_LegendSword);
  }
  if (Playerweapons.WoodenStaff > 0)
  {
  ItemMenu.addItem("Wooden Staff", MenuWep_WoodenStaff);
  }
  if (Playerweapons.BattleStaff > 0)
  {
  ItemMenu.addItem("Battle Staff", MenuWep_BattleStaff);
  }
  if (Playerweapons.MetalStaff > 0)
  {
  ItemMenu.addItem("Metal Staff", MenuWep_MetalStaff);
  }
  if (Playerweapons.MageStaff > 0)
  {
  ItemMenu.addItem("Mage Staff", MenuWep_MageStaff);
  }


  ItemMenu.addItem("Cancel", GameMenu);
  ItemMenu.execute(6, 34, 272, 140);
}

function MenuWep_Dagger()
{
InventoryItem("Dagger", Playerweapons.Dagger, "A simple metal dagger.", "Attack: 5");
}
function MenuWep_Dirk()
{
InventoryItem("Dirk", Playerweapons.Dirk, "A sharp double-bladed knife.", "Attack: 10");
}
function MenuWep_Short_Sword()
{
InventoryItem("Short Sword", Playerweapons.Short_Sword, "Designed like a dagger but with a longer blade for added damage.", "Attack: 15");
}
function MenuWep_MithrilKnife()
{
InventoryItem("Mithril Knife", Playerweapons.MithrilKnife, "A knife made of mithril with notable damage.", "Attack: 45");
}
function MenuWep_ConqudorKnife()
{
InventoryItem("Conqudor Knife", Playerweapons.ConqudorKnife, "A extremely rare knife with damage comparable to even a Mithril Blade.", "Attack: 75");
}
function MenuWep_Long_Sword()
{
InventoryItem("Long Sword", Playerweapons.Long_Sword, "A light metal sword with decent length.", "Attack: 25");
}
function MenuWep_BroadSword()
{
InventoryItem("Broad Sword", Playerweapons.BroadSword, "A heavy sword made from folded iron.", "Attack: 35");
}
function MenuWep_RegalSword()
{
InventoryItem("Regal Sword", Playerweapons.RegalSword, "A sword designed in the 400's for use by generals in battle.", "Attack: 65");
}
function MenuWep_MithrilBlade()
{
InventoryItem("Mithril Blade", Playerweapons.MithrilBlade, "A sword made of mithril that delivers a great deal of damage.", "Attack: 80");
}
function MenuWep_AdamantineBlade()
{
InventoryItem("Adamantine Blade", Playerweapons.AdamantineBlade, "A sword made of the extremely rare metal 'adamantine'.", "Attack: 125");
}
function MenuWep_LegendSword()
{
InventoryItem("Legend Sword", Playerweapons.LegendSword, "A sword of legend and great power.", "Attack: 200");
}
function MenuWep_WoodenStaff()
{
InventoryItem("Wooden Staff", Playerweapons.WoodenStaff, "A crude and simple piece of wood.", "Attack: 12");
}
function MenuWep_BattleStaff()
{
InventoryItem("Battle Staff", Playerweapons.BattleStaff, "A heavy staff meant to provide more damage than a regular staff.", "Attack: 36");
}
function MenuWep_MetalStaff()
{
InventoryItem("Metal Staff", Playerweapons.MetalStaff, "A metal staff that offers a fair amount of damage.", "Attack: 57");
}
function MenuWep_MageStaff()
{
InventoryItem("Mage Staff", Playerweapons.MageStaff, "A metal staff designed for use by mages.", "Attack: 12, Magic Power: + 50%");
}

function MenuItems()
{
  RenderMap();
  
  WindowStyle.drawWindow(8, 8, 624, 12);
  Font.drawText(10, 10, "Items Inventory:");

  // execute the menu
  var ItemMenu = new Menu();
  ItemMenu.font         = Font;
  ItemMenu.window_style = WindowStyle;
  ItemMenu.arrow        = Arrow;
  if (Player.items.potion > 0)
  {
  ItemMenu.addItem("Potion", MenuItems_Potion);
  }
  if (Player.items.hipotion > 0)
  {
  ItemMenu.addItem("Hi-Potion", MenuItems_HiPotion);
  }
  if (Player.items.fullpotion > 0)
  {
  ItemMenu.addItem("Full Potion", MenuItems_FullPotion);
  }
  if (Player.items.ether > 0)
  {
  ItemMenu.addItem("Ether", MenuItems_Ether);
  }
  if (Player.items.turboether > 0)
  {
  ItemMenu.addItem("Turbo Ether", MenuItems_TurboEther);
  }
  if (Player.items.elixer > 0)
  {
  ItemMenu.addItem("Elixer", MenuItems_Elixer);
  }
  if (Player.items.life > 0)
  {
  ItemMenu.addItem("Life", MenuItems_Life);
  }
  if (Player.items.tent > 0)
  {
  ItemMenu.addItem("Tent", MenuItems_Tent);
  }
  if (Phouse[0] >= 1)
  {
  ItemMenu.addItem("Deed", MenuItems_Deed);
  }

  ItemMenu.addItem("Cancel", GameMenu);
  ItemMenu.execute(6, 34, 272, 140);
}

function MenuItems_Potion()
{
InventoryItem("Potion", Player.items.potion, "A combination of medical herbs that recovers a person's hp.", "Hp: 50");
}
function MenuItems_HiPotion()
{
InventoryItem("Hi-Potion", Player.items.hipotion, "A combination of medical herbs like the potion, but with a higher concentration.", "Hp: 250");
}
function MenuItems_FullPotion()
{
InventoryItem("Full Potion", Player.items.fullpotion, "Made from some of the rarest herbs in the world, this potion can fully recover a person's hp.", "Hp: Max");
}
function MenuItems_Ether()
{
InventoryItem("Ether", Player.items.ether, "An expensive mixture that recovers a person's mp.", "Mp: 50");
}
function MenuItems_TurboEther()
{
InventoryItem("Turbo Ether", Player.items.turboether, "An extremely rare item that has the ability to fully recover a person's mp.", "Mp: Max");
}
function MenuItems_Elixer()
{
InventoryItem("Elixer", Player.items.elixer, "An item that can restores a person's Hp and Mp to it's max.  More rare and expensive than the Turbo Ether or the Full Potion.", "Hp and Mp: Max");
}
function MenuItems_Life()
{
InventoryItem("Life", Player.items.life, "The Life potion heals the wounds of an injuried person and restore some of their hp.", "Revives Target");
}
function MenuItems_Tent()
{
InventoryItem("Tent", Player.items.tent, "An outdoors necessity that will allow for a good night's sleep.", "Party Hp and Mp: Max");
}
function MenuItems_Deed()
{
InventoryItem("Deed", 1, "Proof of ownership of the house just east of the Pangara Library.", "Ownership of house");
}


function InventoryItem(name, quanity, description, effect)
{
RenderMap() 
WindowStyle.drawWindow (25, 380, 590, 80);
Font.drawTextBox (45, 380, 500, 60, 5, name);
Font.drawTextBox (45, 390, 500, 60, 5, "Quanity: " + quanity);
Font.drawTextBox (45, 410, 500, 60, 5, description);
Font.drawTextBox (45, 440, 500, 60, 5, effect);
FlipScreen();
while (IsKeyPressed(KEY_SPACE) == false) 
{Delay(100);}
{GetKey()}

Menu_Inventory();
}

function Menu_WhiteMagic()
{
Player.menumagictemp = false;
Player.menumagictempP1 = false;
Player.menumagictempP2 = false;
Player.menumagictempP3 = false;

  if (Player.chrclass == "Mage")
  {
  Player.menumagictemp = true;
  Player.menumagictempP1 = true; 
  }
  else if (Player.chrclass == "Bard")
  {
  Player.menumagictemp = true;
  Player.menumagictempP1 = true;
  }
  if (Player2.pres == true)
  {
    if (Player2.chrclass == "Mage")
    {
    Player.menumagictemp = true;
    Player.menumagictempP2 = true;
    }
    else if (Player2.chrclass == "Bard")
    {
    Player.menumagictemp = true;
    Player.menumagictempP2 = true;
    }
  }
  if (Player3.pres == true)  
  {
    if (Player3.chrclass == "Mage")
    {
    Player.menumagictemp = true;
    Player.menumagictempP3 = true;
    }
    else if (Player3.chrclass == "Bard")
    {
    Player.menumagictemp = true;
    Player.menumagictempP3 = true;
    }
  }

  if (Player.menumagictemp == true)
  {
    RenderMap();
  
    WindowStyle.drawWindow(8, 8, 35, 12);
    Font.drawText(10, 10, "Who?");

    var ItemMenu = new Menu();
    ItemMenu.font         = Font;
    ItemMenu.window_style = WindowStyle;
    ItemMenu.arrow        = Arrow;

    if (Player.menumagictempP1 == true)
    {
    ItemMenu.addItem(Player.name, WMagicMenu1);   
    }    
    if (Player.menumagictempP2 == true)
    {
    ItemMenu.addItem(Player2.name, WMagicMenu2);   
    }    
    if (Player.menumagictempP3 == true)
    {
    ItemMenu.addItem(Player3.name, WMagicMenu3);   
    }    
    ItemMenu.addItem("Cancel", GameMenu);
    ItemMenu.execute(6, 34, 272, 40);

  }
  else
  {
  Talk_Window("No one on your party knows any Magic!", "blank.png");  
  GameMenu()
  }
}

function WMagicMenu1()
{
  if (Player.hp == 0)
  {
  Talk_Window("That person can't cast a spell now.", "blank.png");
  Menu_WhiteMagic();
  }
  else
  {
  Player.active = "Player1";
  WMagicMenu();
  }
}
function WMagicMenu2()
{
  if (Player2.hp == 0)
  {
  Talk_Window("That person can't cast a spell now.", "blank.png");
  Menu_WhiteMagic();
  }
  else
  {
  Player.active = "Player2";
  WMagicMenu();
  }
}
function WMagicMenu3()
{
  if (Player3.hp == 0)
  {
  Talk_Window("That person can't cast a spell now.", "blank.png");
  Menu_WhiteMagic();
  }
  else
  {
  Player.active = "Player3";
  WMagicMenu();
  }
}
function WMagicMenu()
{
  RenderMap();

  WMagicStats();
  
  WindowStyle.drawWindow(8, 8, 90, 12);
  Font.drawText(10, 10, "What spell?");

  var ItemMenu = new Menu();
  ItemMenu.font         = Font;
  ItemMenu.window_style = WindowStyle;
  ItemMenu.arrow        = Arrow;

  if (Player.active == "Player1")
  {
    if (Playerwmagic.cure == true)
    {
    ItemMenu.addItem("Cure", WMagicCure);   
    }  
    if (Playerwmagic.cure2 == true)
    {
    ItemMenu.addItem("Cure 2", WMagicCure2);   
    }  
    if (Playerwmagic.cure3 == true)
    {
    ItemMenu.addItem("Cure 3", WMagicCure3);   
    }  
    if (Playerwmagic.megacure == true)
    {
    ItemMenu.addItem("Mega-Cure", WMagicMegaCure);   
    }  
    if (Playerwmagic.life1 == true)
    {
    ItemMenu.addItem("Life", WMagicLife);   
    }  
    if (Playerwmagic.life2 == true)
    {
    ItemMenu.addItem("Life 2", WMagicLife2);   
    }
    if (Playerwmagic.safe == true)
    {
    ItemMenu.addItem("Safe", WMagicSafe);   
    }      
    if (Playerwmagic.recover == true)
    {
    ItemMenu.addItem("Recover", WMagicRecover);   
    }  
    if (Player.cmagic.encounterpres == true)
    {
    ItemMenu.addItem(Player.cmagic.encounter, WMagicEncounter);   
    }  
  }
  else if (Player.active == "Player2")
  {
    if (Player2wmagic.cure == true)
    {
    ItemMenu.addItem("Cure", WMagicCure);   
    }  
    if (Player2wmagic.cure2 == true)
    {
    ItemMenu.addItem("Cure 2", WMagicCure2);   
    }  
    if (Player2wmagic.cure3 == true)
    {
    ItemMenu.addItem("Cure 3", WMagicCure3);   
    }  
    if (Player2wmagic.megacure == true)
    {
    ItemMenu.addItem("Mega-Cure", WMagicMegaCure);   
    }  
    if (Player2wmagic.life1 == true)
    {
    ItemMenu.addItem("Life", WMagicLife);   
    }  
    if (Player2wmagic.life2 == true)
    {
    ItemMenu.addItem("Life 2", WMagicLife2);   
    }
    if (Player2wmagic.safe == true)
    {
    ItemMenu.addItem("Safe", WMagicSafe);   
    }      
    if (Player2wmagic.recover == true)
    {
    ItemMenu.addItem("Recover", WMagicRecover);   
    }  
  }
  else if (Player.active == "Player3")
  {
    if (Player3wmagic.cure == true)
    {
    ItemMenu.addItem("Cure", WMagicCure);   
    }  
    if (Player3wmagic.cure2 == true)
    {
    ItemMenu.addItem("Cure 2", WMagicCure2);   
    }  
    if (Player3wmagic.cure3 == true)
    {
    ItemMenu.addItem("Cure 3", WMagicCure3);   
    }  
    if (Player3wmagic.megacure == true)
    {
    ItemMenu.addItem("Mega-Cure", WMagicMegaCure);   
    }  
    if (Player3wmagic.life1 == true)
    {
    ItemMenu.addItem("Life", WMagicLife);   
    }  
    if (Player3wmagic.life2 == true)
    {
    ItemMenu.addItem("Life 2", WMagicLife2);   
    }
    if (Player3wmagic.safe == true)
    {
    ItemMenu.addItem("Safe", WMagicSafe);   
    }      
    if (Player3wmagic.recover == true)
    {
    ItemMenu.addItem("Recover", WMagicRecover);   
    }  
  }

  ItemMenu.addItem("Cancel", GameMenu);
  ItemMenu.execute(6, 34, 142, 140);

}
function WMagicCure()
{
CheckMp("Lv1");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GameMenu();
  }
  else
  {    
  Player.temp2 = "Cure";
  WMagicWho();
  }
}
function WMagicCure2()
{
CheckMp("Lv2.5");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GameMenu();
  }
  else
  {
  Player.temp2 = "Cure 2";
  WMagicWho();
  }
}
function WMagicCure3()
{
CheckMp("Lv3.5");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GameMenu();
  }
  else
  {
  Player.temp2 = "Cure 3";
  WMagicAll();
  }
}
function WMagicMegaCure()
{
CheckMp("Lv6");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GameMenu();
  }
  else
  {
  Player.temp2 = "Mega-Cure";
  WMagicAll();
  }
}

function WMagicLife()
{
CheckMp("Lv3");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GameMenu();
  }
  else
  {
  Player.temp2 = "Life";
  WMagicWho();
  }
}
function WMagicLife2()
{
CheckMp("Lv5");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GameMenu();
  }
  else
  {
  Player.temp2 = "Life 2";
  WMagicWho();
  }
}
function WMagicRecover()
{
CheckMp("Lv7");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GameMenu();
  }
  else
  {
  Player.temp2 = "Recover";
  WMagicAll();
  }
}
function WMagicSafe()
{
CheckMp("Lv5");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GameMenu();
  }
  else if (Player.items.tent > 0)
  {
    RenderMap()
    FadeToColor(500, Black);
    
    if (Player.hp > 0)
    {
    Player.hp = Player.maxhp;
    Player.mp = Player.maxmp;
    }
    if (Player2.pres == true)
    {
      if (Player2.hp > 0)
      {
      Player2.hp = Player2.maxhp;
      Player2.mp = Player2.maxmp;
      }        
    }
    if (Player3.pres == true)
    {
      if (Player3.hp > 0)
      {
      Player3.hp = Player3.maxhp;
      Player3.mp = Player3.maxmp;
      }        
    }
    Delay(500);
    FadeFromColor(500, Black);
    Talk_Window("Hp and Mp Restored!", Player.port); 
    Player.items.tent = Player.items.tent - 1;  
    ReduceMp("Lv5");
  }
  else
  {
  Talk_Window("You don't have a tent!", "blank.png");
  GameMenu();
  }
GarbageCollect();
}
function WMagicEncounter()
{
CheckMp("Lv2");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GameMenu();
  }
  else
  {
  EncounterMenu();
  }
}
function EncounterMenu()
{
  RenderMap();
  
  WindowStyle.drawWindow(8, 8, 100, 12);
  Font.drawText(10, 10, "Change to:");

  // execute the menu
  var wmagicmenu = new Menu();
  wmagicmenu.font         = Font;
  wmagicmenu.window_style = WindowStyle;
  wmagicmenu.arrow        = Arrow;
  wmagicmenu.addItem("High",  WMagicEHigh);
  wmagicmenu.addItem("Normal",  WMagicENormal);
  wmagicmenu.addItem("Low",  WMagicELow);
  wmagicmenu.addItem("Cancel", WMagicMenu);
  wmagicmenu.execute(6, 34, 102, 60);
}
function WMagicEHigh()
{
ReduceMp("Lv2");
Talk_Window("Encounter rate set to high.", "blank.png");
Player.engage = 40;
GameMenu();
}
function WMagicENormal()
{
ReduceMp("Lv2");
Talk_Window("Encounter rate set to normal.", "blank.png");
Player.engage = 60;
GameMenu();
}
function WMagicELow()
{
ReduceMp("Lv2");
Talk_Window("Encounter rate set to low.", "blank.png");
Player.engage = 90;
GameMenu();
}

function WMagicWho()
{
  RenderMap();

  WMagicStats();
  
  WindowStyle.drawWindow(8, 8, 100, 12);
  Font.drawText(10, 10, "Cast on who?");

  // execute the menu
  var wmagicmenu = new Menu();
  wmagicmenu.font         = Font;
  wmagicmenu.window_style = WindowStyle;
  wmagicmenu.arrow        = Arrow;
  wmagicmenu.addItem(Player.name,  WMagicTargetP1);
  if (Player2.pres == true)
  {
  wmagicmenu.addItem(Player2.name,  WMagicTargetP2);
  }
  if (Player3.pres == true)
  {
  wmagicmenu.addItem(Player3.name,  WMagicTargetP3);
  }  
  wmagicmenu.addItem("Cancel",  WMagicMenu);
  wmagicmenu.execute(6, 34, 142, 40);
}

function WMagicStats()
{
WindowStyle.drawWindow(158, 34, 477, 40);

  Font.drawText(165, 39, Player.name + " Hp: " + Player.hp + "/" + Player.maxhp + " Mp: " + Player.mp + "/" + Player.maxmp);
  if (Player2.pres == true)
  {
  Font.drawText(165, 49, Player2.name + " Hp: " + Player2.hp + "/" + Player2.maxhp + " Mp: " + Player2.mp + "/" + Player2.maxmp);
  }
  if (Player3.pres == true)
  {
  Font.drawText(165, 59, Player3.name + " Hp: " + Player3.hp + "/" + Player3.maxhp + " Mp: " + Player3.mp + "/" + Player3.maxmp);
  }

}

function WMagicTargetP1()
{
GetMagStats()
Player.mathtemp = Math.random()/5 + 0.9;
  if (Player.active == "Player1")
  {
    if (Player.APlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }
  else if (Player.active == "Player2")
  {
    if (Player2.APlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }
  else if (Player.active == "Player3")
  {
    if (Player3.APlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }

  if (Player.temp2 == "Cure")
  {
    if (Player.hp == 0)
    {
    Talk_Window("That can't be cast on a wounded person.", "blank.png");
    WMagicMenu();
    }
    else
    {
    ReduceMp("Lv1")
    Player.hp = Player.hp + Math.floor(Player.mattacktemp*Player.mathtemp);
    SetHpToMax();
    WMagicMenu();
    }
  }
  else if (Player.temp2 == "Cure 2")
  {
    if (Player.hp == 0)
    {
    Talk_Window("That can't be cast on a wounded person.", "blank.png");
    WMagicMenu();
    }
    else
    {
    ReduceMp("Lv2.5")
    Player.hp = Player.hp + Math.floor(Player.mattacktemp*Player.mathtemp)*3;
    SetHpToMax();
    WMagicMenu();
    }
  }
  else if (Player.temp2 == "Life")
  {
    if (Player.hp == 0)
    {
    ReduceMp("Lv3")
    Player.hp = Player.maxhp/5;
    WMagicMenu();
    }
    else
    {
    ReduceMp("Lv3")
    Talk_Window("Ineffective.", "blank.png");
    WMagicMenu();
    }
  }
  else if (Player.temp2 == "Life 2")
  {
    if (Player.hp == 0)
    {
    ReduceMp("Lv5")
    Player.hp = Player.maxhp;
    WMagicMenu();
    }
    else
    {
    ReduceMp("Lv5")
    Talk_Window("Ineffective.", "blank.png");
    WMagicMenu();
    }
  }
}
function WMagicTargetP2()
{
GetMagStats()
Player.mathtemp = Math.random()/5 + 0.9;
  if (Player.active == "Player1")
  {
    if (Player.APlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }
  else if (Player.active == "Player2")
  {
    if (Player2.APlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }
  else if (Player.active == "Player3")
  {
    if (Player3.APlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }

  if (Player.temp2 == "Cure")
  {
    if (Player2.hp == 0)
    {
    Talk_Window("That can't be cast on a wounded person.", "blank.png");
    WMagicMenu();
    }
    else
    {
    ReduceMp("Lv1")
    Player2.hp = Player2.hp + Math.floor(Player.mattacktemp*Player.mathtemp);
    SetHpToMax();
    WMagicMenu();
    }
  }
  else if (Player.temp2 == "Cure 2")
  {
    if (Player2.hp == 0)
    {
    Talk_Window("That can't be cast on a wounded person.", "blank.png");
    WMagicMenu();
    }
    else
    {
    ReduceMp("Lv2.5")
    Player2.hp = Player2.hp + Math.floor(Player.mattacktemp*Player.mathtemp)*3;
    SetHpToMax();
    WMagicMenu();
    }
  }
  else if (Player.temp2 == "Life")
  {
    if (Player2.hp == 0)
    {
    ReduceMp("Lv3")
    Player2.hp = Player2.maxhp/5;
    WMagicMenu();
    }
    else
    {
    ReduceMp("Lv3")
    Talk_Window("Ineffective.", "blank.png");
    WMagicMenu();
    }
  }
  else if (Player.temp2 == "Life 2")
  {
    if (Player2.hp == 0)
    {
    ReduceMp("Lv5")
    Player2.hp = Player2.maxhp;
    WMagicMenu();
    }
    else
    {
    ReduceMp("Lv5")
    Talk_Window("Ineffective.", "blank.png");
    WMagicMenu();
    }
  }
}
function WMagicTargetP3()
{
GetMagStats()
Player.mathtemp = Math.random()/5 + 0.9;
  if (Player.active == "Player1")
  {
    if (Player.APlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }
  else if (Player.active == "Player2")
  {
    if (Player2.APlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }
  else if (Player.active == "Player3")
  {
    if (Player3.APlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }

  if (Player.temp2 == "Cure")
  {
    if (Player3.hp == 0)
    {
    Talk_Window("That can't be cast on a wounded person.", "blank.png");
    WMagicMenu();
    }
    else
    {
    ReduceMp("Lv1")
    Player3.hp = Player3.hp + Math.floor(Player.mattacktemp*Player.mathtemp);
    SetHpToMax();
    WMagicMenu();
    }
  }
  else if (Player.temp2 == "Cure 2")
  {
    if (Player3.hp == 0)
    {
    Talk_Window("That can't be cast on a wounded person.", "blank.png");
    WMagicMenu();
    }
    else
    {
    ReduceMp("Lv2.5")
    Player3.hp = Player3.hp + Math.floor(Player.mattacktemp*Player.mathtemp)*3;
    SetHpToMax();
    WMagicMenu();
    }
  }
  else if (Player.temp2 == "Life")
  {
    if (Player3.hp == 0)
    {
    ReduceMp("Lv3")
    Player3.hp = Player3.maxhp/5;
    WMagicMenu();
    }
    else
    {
    ReduceMp("Lv3")
    Talk_Window("Ineffective.", "blank.png");
    WMagicMenu();
    }
  }
  else if (Player.temp2 == "Life 2")
  {
    if (Player3.hp == 0)
    {
    ReduceMp("Lv5")
    Player3.hp = Player3.maxhp;
    WMagicMenu();
    }
    else
    {
    ReduceMp("Lv5")
    Talk_Window("Ineffective.", "blank.png");
    WMagicMenu();
    }
  }
}

function WMagicAll()
{
GetMagStats()
Player.mathtemp = Math.random()/5 + 0.9;
  if (Player.active == "Player1")
  {
    if (Player.APlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }
  else if (Player.active == "Player2")
  {
    if (Player2.APlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }
  else if (Player.active == "Player3")
  {
    if (Player3.APlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }

  if (Player.temp2 == "Cure 3")
  {
    ReduceMp("Lv3.5")
    if (Player.hp > 0)
    {
    Player.hp = Player.hp + Math.floor(Player.mattacktemp*Player.mathtemp)*5;
    }
    if (Player2.pres == true)
    {
      if (Player2.hp > 0)
      {
      Player2.hp = Player2.hp + Math.floor(Player.mattacktemp*Player.mathtemp)*5;
      }
    }
    if (Player3.pres == true)
    {
      if (Player3.hp > 0)
      {
      Player3.hp = Player3.hp + Math.floor(Player.mattacktemp*Player.mathtemp)*5;
      }
    }
    SetHpToMax();
    WMagicMenu();
  }
  else if (Player.temp2 == "Mega-Cure")
  {
    ReduceMp("Lv6")
    if (Player.hp > 0)
    {
    Player.hp = Player.hp + Math.floor(9000*(Math.random()/5 + 0.9));
    }
    if (Player2.pres == true)
    {
      if (Player2.hp > 0)
      {
      Player2.hp = Player2.hp + Math.floor(9000*(Math.random()/5 + 0.9));
      }
    }
    if (Player3.pres == true)
    {
      if (Player3.hp > 0)
      {
      Player3.hp = Player3.hp + Math.floor(9000*(Math.random()/5 + 0.9));
      }
    }
    SetHpToMax();
    WMagicMenu();
  }
  else if (Player.temp2 == "Recover")
  {
    ReduceMp("Lv7")
    Player.hp = Player.maxhp;
    if (Player2.pres == true)
    {
    Player2.hp = Player2.maxhp;
    }
    if (Player3.pres == true)
    {
    Player3.hp = Player3.maxhp;
    }
    WMagicMenu();
  }
}

function SetHpToMax()
{
  if (Player.hp > Player.maxhp)
  { 
  Player.hp = Player.maxhp;
  }
  
  if (Player2.pres == true)
  {
    if (Player2.hp > Player2.maxhp)
    {
    Player2.hp = Player2.maxhp;
    }
  }

  if (Player3.pres == true)
  {
    if (Player3.hp > Player3.maxhp)
    {
    Player3.hp = Player3.maxhp;
    }
  }
}

